package com.inspectortime.webapp;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.inspectortime.util.SpringValidatorUtils;
import com.mkode.util.java.lang.ClassUtils;

/**
 * Validates the Customer Information page in the Wizard.  
 *  
 * @author bones
 *
 */
public class InspectionCustomerInformationValidator implements Validator {

	public boolean supports(Class clazz) {
		return ClassUtils.isInstanceOf(clazz, InspectionCriteria.class);
	}

	public void validate(Object target, Errors errors) {

		InspectionCriteria inspectionCriteria = (InspectionCriteria) target;
				
		if (!SpringValidatorUtils.isEmptyOrWhitespace(errors, "inspection.homeBuyer.secondaryPhone")) {
			SpringValidatorUtils.rejectInvalidPhone(errors, "inspection.homeBuyer.secondaryPhone");	
		}		
		if (!SpringValidatorUtils.isEmptyOrWhitespace(errors, "inspection.homeBuyer.fax")) {
			SpringValidatorUtils.rejectInvalidPhone(errors, "inspection.homeBuyer.fax");	
		}
		if (!SpringValidatorUtils.isEmptyOrWhitespace(errors, "inspection.homeBuyer.address.zipCode")) {
			SpringValidatorUtils.rejectInvalidZip(errors, "inspection.homeBuyer.address.zipCode");	
		}
		if (!SpringValidatorUtils.isEmptyOrWhitespace(errors, "secondHomeBuyer.email")) {
			SpringValidatorUtils.rejectInvalidEmail(errors, "secondHomeBuyer.email");	
		}
		if (!SpringValidatorUtils.isEmptyOrWhitespace(errors, "secondHomeBuyer.phone")) {
			SpringValidatorUtils.rejectInvalidPhone(errors, "secondHomeBuyer.phone");	
		}
		
	}
}
